//
//  SmallDecisionsHomeCell.m
//  SmallDecisions
//
//  Created by 李付雄 on 2025/7/25.
//

#import "SmallDecisionsHomeCell.h"

@interface SmallDecisionsHomeCell()
@property (nonatomic, strong) UIView *containView;

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *iconImageView;

@end

@implementation SmallDecisionsHomeCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if(self) {
        self.contentView.backgroundColor = [UIColor clearColor];
        UIView *selectedBackgroundView = [[UIView alloc] init];
        selectedBackgroundView.backgroundColor = [UIColor clearColor];
        self.selectedBackgroundView = selectedBackgroundView;
    }
    return self;
}


- (void)setModel:(SmallDecisionsHomeModel *)model {
    _model = model;
    self.containView.backgroundColor = [UIColor colorWithHexString:model.bgColor];
    self.titleLabel.text = model.title;
    self.iconImageView.image = [UIImage imageNamed:model.icon];
}

- (UIView *)containView {
    if(!_containView) {
        _containView = [[UIView alloc] init];
        [self.contentView addSubview:_containView];
        [_containView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_offset(0);
            make.right.bottom.mas_offset(0);
        }];
        _containView.layer.cornerRadius  = 8;
        _containView.layer.shadowColor   = SmallDecisionsBgColor.CGColor;
        _containView.layer.shadowOpacity = 0.2;
        _containView.layer.shadowOffset  = CGSizeMake(0, 0);
        _containView.layer.shadowRadius  = 2;
        _containView.layer.masksToBounds = YES;
    }
    return _containView;
}


- (UILabel *)titleLabel {
    if(!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = SmallDecisionsSetBoldFontSize(16);
        _titleLabel.textColor = SmallDecisionsThemeFontColor;
        _titleLabel.numberOfLines = 0;
        _titleLabel.textAlignment = 1;
        _titleLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
        [self.containView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_offset(0);
            make.height.mas_offset(40);
            make.bottom.mas_offset(0);
        }];
    }
    return _titleLabel;
}

- (UIImageView *)iconImageView {
    if(!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.containView addSubview:_iconImageView];
        [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_offset(0);
            make.centerY.mas_offset(-20);
            make.width.mas_offset(60);
        }];
    }
    return _iconImageView;
}



@end
